home *** CD-ROM | disk | FTP | other *** search
- // animation.cnh
-
- // message
- message StartAnim();
- message StopAnim();
- message PauseAnim();
- message AnimEnded(Gui_Component _pthis);
-
- // Mutator
- func void Add_TranslateAnim(Gui_Component _poComponent,i32x _iPosX,i32x _iPosY,f32x _fSpeed);
- func void Add_TranslateScaleAnim(Gui_Component _poComponent,i32x _iPosX,i32x _iPosY,f32x _fScale,f32x _fSpeed);
- func void Add_FonduAnim(Gui_Component _poComponent,i32x _iEndColor,f32x _fSpeed);
- func void Add_Viewer3D(Gui_Component _poComponent,f32x _fMinRx,f32x _fMaxRx,f32x _fMinRy,f32x _fMaxRy,f32x _fSpeeRx,f32x _fSpeedRy);
-
- // -------------------------------------------------------------
- // Standard animation interface
- // -------------------------------------------------------------
- var i32x ANIM_STOPPED = 0;
- var i32x ANIM_RUNNING = 1;
- var i32x ANIM_PAUSED = 2;
- var i32x ANIM_ENDED = 3;
-
- func void FonduAnim_Start();
- func void FonduAnim_Stop();
- func void FonduAnim_Pause();
-
- func void TranslateAnim_Start();
- func void TranslateAnim_Stop();
- func void TranslateAnim_Pause();
-
- func void TranslateScaleAnim_Start();
- func void TranslateScaleAnim_Stop();
- func void TranslateScaleAnim_Pause();
-
- func i32x Viewer3D_OnLoop(f32x _fDeltaTime);
- func i32x Viewer3D_OnMouseMove(i32x _iX,i32x _iY);
- // Data class
- class Gui_dtAnimTranslate
- {
- var i32x iStartPosX;
- var i32x iStartPosY;
- var i32x iFinalPosX;
- var i32x iFinalPosY;
- var f32x fTheta;
- var f32x fSpeed; // In rad per second
- var i32x iState; // AnimState
- };
-
- class Gui_dtAnimScaleTranslate
- {
- var f32x fStartScale;
- var f32x fFinalScale;
- var i32x iStartPosX;
- var i32x iStartPosY;
- var i32x iFinalPosX;
- var i32x iFinalPosY;
- var f32x fTheta;
- var f32x fSpeed; // In rad per second
- var i32x iState; // AnimState
- };
- class Gui_dtAnimFondu
- {
- var i32x iRs;
- var i32x iGs;
- var i32x iBs;
- var i32x iAs;
- var i32x iRe;
- var i32x iGe;
- var i32x iBe;
- var i32x iAe;
- var f32x fTheta;
- var f32x fSpeed; // In rad per second
- var i32x iState; // AnimState
- };
-
- class Gui_dtViewer3D
- {
- var f32x fMinRx;
- var f32x fMinRy;
- var f32x fMaxRx;
- var f32x fMaxRy;
- var f32x fRx;
- var f32x fRy;
- var i32x iOx;
- var i32x iOy;
- var f32x fSpeedRx;
- var f32x fSpeedRy;
- };
-
- func i32x TranslateLoop(f32x _fDelta);
- func i32x TranslateScaleLoop(f32x _fDelta);
- func i32x FonduLoop(f32x _fDelta);
-
- interface Gui_iAnim_Translate
- {
- // Standard anim message
- TranslateAnim_Start StartAnim;
- TranslateAnim_Stop StopAnim;
- TranslateAnim_Pause PauseAnim;
-
- // Loop implementation
- TranslateLoop Loop;
- }
-
- interface Gui_iAnim_TranslateScale
- {
- // Standard anim message
- TranslateScaleAnim_Start StartAnim;
- TranslateScaleAnim_Stop StopAnim;
- TranslateScaleAnim_Pause PauseAnim;
-
- // Loop implementation
- TranslateScaleLoop Loop;
- }
-
- interface Gui_iAnim_Fondu
- {
- // Standard anim message
- FonduAnim_Start StartAnim;
- FonduAnim_Stop StopAnim;
- FonduAnim_Pause PauseAnim;
-
- // Loop implementation
- FonduLoop Loop;
- }
-
- interface Gui_iViewer3D
- {
- Viewer3D_OnMouseMove MouseMove;
- Viewer3D_OnLoop Loop;
- }
-
- func void Add_FonduAnim(Gui_Component _poComponent,i32x _iEndColor,f32x _fSpeed)
- {
- var Gui_dtAnimFondu pdtData;
-
- // New fonud anim data
- pdtData = new Gui_dtAnimFondu;
- pdtData.iRs = GetRed(GetModulateColor(_poComponent));
- pdtData.iGs = GetGreen(GetModulateColor(_poComponent));
- pdtData.iBs = GetBlue(GetModulateColor(_poComponent));
- pdtData.iAs = GetAlpha(GetModulateColor(_poComponent));
- pdtData.iRe = GetRed(_iEndColor);
- pdtData.iGe = GetGreen(_iEndColor);
- pdtData.iBe = GetBlue(_iEndColor);
- pdtData.iAe = GetAlpha(_iEndColor);
- pdtData.fTheta = 0.0;
- pdtData.fSpeed = _fSpeed;
- pdtData.iState = ANIM_STOPPED;
-
- // Add interface to component
- AddInterface(_poComponent,Gui_iAnim_Fondu,pdtData);
- }
-
- func void Add_TranslateAnim(Gui_Component _poComponent,i32x _iPosX,i32x _iPosY,f32x _fSpeed)
- {
- var Gui_dtAnimTranslate pdtTrans;
-
- // New translation anim data
- pdtTrans = new Gui_dtAnimTranslate;
- pdtTrans.iStartPosX = RelPosX(_poComponent);
- pdtTrans.iStartPosY = RelPosY(_poComponent);
- pdtTrans.iFinalPosX = _iPosX;
- pdtTrans.iFinalPosY = _iPosY;
- pdtTrans.fTheta = 0.0;
- pdtTrans.fSpeed = _fSpeed;
- pdtTrans.iState = ANIM_STOPPED;
-
- // Add interface to component
- AddInterface(_poComponent,Gui_iAnim_Translate,pdtTrans);
- }
- func void Add_TranslateScaleAnim(Gui_Component _poComponent,i32x _iPosX,i32x _iPosY,f32x _fScale,f32x _fSpeed)
- {
- var Gui_dtAnimScaleTranslate pdtTrans;
-
- // New translation anim data
- pdtTrans = new Gui_dtAnimScaleTranslate;
- pdtTrans.iStartPosX = RelPosX(_poComponent);
- pdtTrans.iStartPosY = RelPosY(_poComponent);
- pdtTrans.iFinalPosX = _iPosX;
- pdtTrans.iFinalPosY = _iPosY;
- pdtTrans.fStartScale = GetScale(_poComponent);
- pdtTrans.fFinalScale = _fScale;
- pdtTrans.fTheta = 0.0;
- pdtTrans.fSpeed = _fSpeed;
- pdtTrans.iState = ANIM_STOPPED;
-
- // Add interface to component
- AddInterface(_poComponent,Gui_iAnim_TranslateScale,pdtTrans);
- }
-
- func void Add_Viewer3D(Gui_Component _poComponent,f32x _fMinRx,f32x _fMaxRx,f32x _fMinRy,f32x _fMaxRy,f32x _fSpeeRx,f32x _fSpeedRy)
- {
- var Gui_dtViewer3D pdtData;
-
- // New viewer 3d data
- pdtData = new Gui_dtViewer3D;
- pdtData.fMinRx = _fMinRx;
- pdtData.fMinRy = _fMinRy;
- pdtData.fMaxRx = _fMaxRx;
- pdtData.fMaxRy = _fMaxRy;
- pdtData.fRx = 0.0;
- pdtData.fRy = 0.0;
- pdtData.iOx = 0;
- pdtData.iOy = 0;
-
- pdtData.fSpeedRx = _fSpeeRx;
- pdtData.fSpeedRy = _fSpeedRy;
-
- // Add interface to component
- AddInterface(_poComponent,Gui_iViewer3D,pdtData);
- }
-
- func void TranslateAnim_Start()
- {
- var Gui_Component pthis;
- var Gui_dtAnimTranslate pdtData;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- // Change anim state
- pdtData.iState = ANIM_RUNNING;
- }
-
- func void TranslateAnim_Stop()
- {
- var Gui_Component pthis;
- var Gui_dtAnimTranslate pdtData;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- // Change anim state
- pdtData.iState = ANIM_STOPPED;
- pdtData.fTheta = 0.0;
- }
-
- func void TranslateAnim_Pause()
- {
- var Gui_Component pthis;
- var Gui_dtAnimTranslate pdtData;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- // Change anim state
- pdtData.iState = ANIM_PAUSED;
- }
-
- func void TranslateScaleAnim_Start()
- {
- var Gui_Component pthis;
- var Gui_dtAnimScaleTranslate pdtData;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- // Change anim state
- pdtData.iState = ANIM_RUNNING;
- }
-
- func void TranslateScaleAnim_Stop()
- {
- var Gui_Component pthis;
- var Gui_dtAnimScaleTranslate pdtData;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- // Change anim state
- pdtData.iState = ANIM_STOPPED;
- pdtData.fTheta = 0.0;
- }
-
- func void TranslateScaleAnim_Pause()
- {
- var Gui_Component pthis;
- var Gui_dtAnimScaleTranslate pdtData;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- // Change anim state
- pdtData.iState = ANIM_PAUSED;
- }
-
- func void FonduAnim_Start()
- {
- var Gui_Component pthis;
- var Gui_dtAnimFondu pdtData;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- // Change anim state
- pdtData.iState = ANIM_RUNNING;
- }
-
- func void FonduAnim_Stop()
- {
- var Gui_Component pthis;
- var Gui_dtAnimFondu pdtData;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- // Change anim state
- pdtData.iState = ANIM_STOPPED;
- pdtData.fTheta = 0.0;
- }
-
- func void FonduAnim_Pause()
- {
- var Gui_Component pthis;
- var Gui_dtAnimFondu pdtData;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- // Change anim state
- pdtData.iState = ANIM_PAUSED;
- }
-
- func i32x FonduLoop(f32x _fDelta)
- {
- var Gui_Component pthis,pparent;
- var Gui_dtAnimFondu pdtData;
- var f32x pcos;
- var f32x fRs,fAs,fBs,fGs;
- var f32x fRe,fAe,fBe,fGe;
- var f32x fRc,fAc,fBc,fGc;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- if(pdtData.iState == ANIM_RUNNING)
- {
- // Current Position
- pdtData.fTheta = pdtData.fTheta + pdtData.fSpeed * _fDelta;
- if(pdtData.fTheta>MATH_PI)
- pdtData.fTheta = MATH_PI;
-
- pcos = 1.0 - ((cos(pdtData.fTheta)+1.0) * 0.5);
-
- fRs = pdtData.iRs;
- fGs = pdtData.iGs;
- fBs = pdtData.iBs;
- fAs = pdtData.iAs;
-
-
- fRe = pdtData.iRe;
- fGe = pdtData.iGe;
- fBe = pdtData.iBe;
- fAe = pdtData.iAe;
-
- // Compute new modulate color
- fRc = fRs + pcos * (fRe - fRs);
- fGc = fGs + pcos * (fGe - fGs);
- fBc = fBs + pcos * (fBe - fBs);
- fAc = fAs + pcos * (fAe - fAs);
-
- if(pdtData.fTheta==MATH_PI)
- {
- // End Anim
- pdtData.iState = ANIM_ENDED;
- }
-
- // Update modulate color
- SetModulateColor(pthis,MakeARGB(fAc,fRc,fGc,fBc));
- }
- else if(pdtData.iState == ANIM_ENDED)
- {
- // Remove loop interface
- RemoveInterface(pthis);
- pparent = GetParent(pthis);
- if(pparent)
- pparent<<AnimEnded(pthis);
- }
- }
- func i32x TranslateLoop(f32x _fDelta)
- {
- var Gui_Component pthis,pparent;
- var Gui_dtAnimTranslate pdtData;
- var f32x fSX,fSY,fFX,fFY,pcos,fPosX,fPosY;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- if(pdtData.iState == ANIM_RUNNING)
- {
- // Current Position
- pdtData.fTheta = pdtData.fTheta + pdtData.fSpeed * _fDelta;
- if(pdtData.fTheta>MATH_PI)
- pdtData.fTheta = MATH_PI;
-
- pcos = 1.0 - ((cos(pdtData.fTheta)+1.0) * 0.5);
-
- fSX = pdtData.iStartPosX;
- fSY = pdtData.iStartPosY;
-
- fFX = pdtData.iFinalPosX;
- fFY = pdtData.iFinalPosY;
-
- // Compute new position
- fPosX = fSX + pcos * (fFX - fSX);
- fPosY = fSY + pcos * (fFY - fSY);
-
- if(pdtData.fTheta==MATH_PI)
- {
- // End Anim
- pdtData.iState = ANIM_ENDED;
- }
-
- // Move component
- MoveTo(pthis,fPosX,fPosY);
- }
- else if(pdtData.iState == ANIM_ENDED)
- {
- pparent = GetParent(pthis);
- if(pparent)
- pparent<<AnimEnded(pthis);
- // Remove loop interface
- RemoveInterface(pthis);
- }
- }
-
- func i32x TranslateScaleLoop(f32x _fDelta)
- {
- var Gui_Component pthis,pparent;
- var Gui_dtAnimScaleTranslate pdtData;
- var f32x fSScale,fFScale,fScale,fSX,fSY,fFX,fFY,pcos,fPosX,fPosY;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
-
- if(pdtData.iState == ANIM_RUNNING)
- {
- // Current Position
- pdtData.fTheta = pdtData.fTheta + pdtData.fSpeed * _fDelta;
- if(pdtData.fTheta>MATH_PI)
- pdtData.fTheta = MATH_PI;
-
- pcos = 1.0 - ((cos(pdtData.fTheta)+1.0) * 0.5);
-
- fSScale = pdtData.fStartScale;
- fSX = pdtData.iStartPosX;
- fSY = pdtData.iStartPosY;
-
- fFScale = pdtData.fFinalScale;
- fFX = pdtData.iFinalPosX;
- fFY = pdtData.iFinalPosY;
-
- // Compute new position
- fPosX = fSX + pcos * (fFX - fSX);
- fPosY = fSY + pcos * (fFY - fSY);
- fScale = fSScale + pcos * (fFScale - fSScale);
-
- if(pdtData.fTheta==MATH_PI)
- {
- // End Anim
- pdtData.iState = ANIM_ENDED;
- }
-
- // Move component
- MoveTo(pthis,fPosX,fPosY);
- SetScale(pthis,fScale);
- }
- else if(pdtData.iState == ANIM_ENDED)
- {
- pparent = GetParent(pthis);
- if(pparent)
- pparent<<AnimEnded(pthis);
- // Remove loop interface
- RemoveInterface(pthis);
- }
- }
-
- func i32x Viewer3D_OnMouseMove(i32x _iX,i32x _iY)
- {
- var Gui_Component pthis,pparent;
- var Gui_dtViewer3D pdtData;
- var f32x dx,dy;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
- if(GetKeyState(VK_LButton))
- {
- // Rotate
- pdtData.fRx = pdtData.fRx + 0.018*(_iY - pdtData.iOy);
- pdtData.fRy = pdtData.fRy + 0.018*(_iX - pdtData.iOx);
- if(!((pdtData.fMaxRx == MATH_2PI)&&(pdtData.fMinRx == 0.0)))
- {
- if(pdtData.fRx>pdtData.fMaxRx)
- pdtData.fRx = pdtData.fMaxRx;
- if(pdtData.fRx<pdtData.fMinRx)
- pdtData.fRx = pdtData.fMinRx;
- }
- if(!((pdtData.fMaxRy == MATH_2PI)&&(pdtData.fMinRy == 0.0)))
- {
- if(pdtData.fRy>pdtData.fMaxRy)
- pdtData.fRy = pdtData.fMaxRy;
- if(pdtData.fRy<pdtData.fMinRy)
- pdtData.fRy = pdtData.fMinRy;
- }
- Rotate(GetSprite(pthis),pdtData.fRx,pdtData.fRy,0.0);
- }
- pdtData.iOx = _iX;
- pdtData.iOy = _iY;
- return 0;
- }
-
- func i32x Viewer3D_OnLoop(f32x _fDeltaTime)
- {
- var Gui_Component pthis,pparent;
- var Gui_dtViewer3D pdtData;
- var f32x dx,dy;
-
- // Retrieve this pointer
- pthis = GetThis();
-
- // Retrieve translation data
- pdtData = GetData(pthis);
- // Rotate
- if(pdtData.fSpeedRx!=0.0)
- {
- pdtData.fRx = pdtData.fRx + pdtData.fSpeedRx*_fDeltaTime;
- if(!((pdtData.fMaxRx == MATH_2PI)&&(pdtData.fMinRx == 0.0)))
- {
- if(pdtData.fRx>pdtData.fMaxRx)
- pdtData.fRx = pdtData.fMaxRx;
- if(pdtData.fRx<pdtData.fMinRx)
- pdtData.fRx = pdtData.fMinRx;
- }
- }
-
- if(pdtData.fSpeedRy!=0.0)
- {
- pdtData.fRy = pdtData.fRy + pdtData.fSpeedRy*_fDeltaTime;
- if(!((pdtData.fMaxRy == MATH_2PI)&&(pdtData.fMinRy == 0.0)))
- {
- if(pdtData.fRy>pdtData.fMaxRy)
- pdtData.fRy = pdtData.fMaxRy;
- if(pdtData.fRy<pdtData.fMinRy)
- pdtData.fRy = pdtData.fMinRy;
- }
- }
-
- Rotate(GetSprite(pthis),pdtData.fRx,pdtData.fRy,0.0);
-
- return 1;
- }
-